<!DOCTYPE html>
<html>
<head>
    {include file="public/header" /}
    <style>
        .layui-card {
            border: 1px solid #f2f2f2;
            border-radius: 5px;
        }

        .layuimini-qiuck-module a i {
            display: inline-block;
            width: 100%;
            height: 60px;
            line-height: 60px;
            text-align: center;
            border-radius: 2px;
            font-size: 30px;
            background-color: #F8F8F8;
            color: #333;
            transition: all .3s;
            -webkit-transition: all .3s;
        }

        .layuimini-qiuck-module a cite {
            position: relative;
            top: 2px;
            display: block;
            color: #666;
            text-overflow: ellipsis;
            overflow: hidden;
            white-space: nowrap;
            font-size: 14px;
        }

        .welcome-module {
            width: 100%;
        }

        .panel {
            background-color: #fff;
            border: 1px solid transparent;
            border-radius: 3px;
            -webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, .05);
            box-shadow: 0 1px 1px rgba(0, 0, 0, .05);
            text-align: center;
        }

        .panel-body {
            padding: 10px
        }

        .panel-title {
            margin-top: 0;
            margin-bottom: 0;
            font-size: 12px;
            color: inherit
        }

        .main_btn > p {
            height: 40px;
        }

        .layui-bg-number {
            background-color: #F8F8F8;
        }

        .no-margins {
            color: #00a2d4;
        }

    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <!--<fieldset class="table-search-fieldset">-->
            <div class="layui-row layui-col-space10">
                <form class="layui-form layui-form-pane" action="" style="float: left">
                    <div style="margin: 10px 10px 10px 10px">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">搜索信息</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="search" autocomplete="off" placeholder="按【生意名称】搜索" class="layui-input soso">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">周期</label>
                                <div class="layui-input-inline" style="width: 100px;">
                                    <input type="number" name="min" autocomplete="off" placeholder="基础价值" class="layui-input soso">
                                </div>
                                <div class="layui-form-mid">-</div>
                                <div class="layui-input-inline" style="width: 100px;">
                                    <input type="number" name="max" autocomplete="off" placeholder="最高价值" class="layui-input soso">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">收益</label>
                                <div class="layui-input-inline" style="width: 100px;">
                                    <input type="number" name="min_income" autocomplete="off" placeholder="最小值" class="layui-input soso">
                                </div>
                                <div class="layui-form-mid">-</div>
                                <div class="layui-input-inline" style="width: 100px;">
                                    <input type="number" name="max_income" autocomplete="off" placeholder="最大值" class="layui-input soso">
                                </div>
                            </div>
                            <div class="layui-inline" style="display: none">
                                <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                            </div>
                        </div>

                    </div>
                </form>
                <div class="layui-col-xs2" style="float: right" >
                    <div class="panel layui-bg-number">
                        <div class="panel-body">
                            <div class="panel-title">
                                <h2>当前出售生意数量</h2>
                            </div>
                            <div class="panel-content">
                                <h2 class="no-margins">{$currentSales}</h2>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs2" style="float: right">
                    <div class="panel layui-bg-number">
                        <div class="panel-body">
                            <div class="panel-title">
                                <h2>当前需购买数量</h2>
                            </div>
                            <div class="panel-content">
                                <h2 class="no-margins">{$needBuy}</h2>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        <!--</fieldset>-->
        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="lanunch">投放管理</button>
            </div>
        </script>
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
        <script type="text/html" id="currentTableBar">
            <!--<a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="LaunchIndustry">投放行业</a>-->
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="detail">查看详情</a>
        </script>
        <input type="hidden" id="memberCode">
    </div>
</div>
{include file="public/footer" /}
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;
        /*用户卡券*/
        table.render({
            elem: '#currentTableId',
            url: '/admin/TransactionData/proportionToBeSold?action=ajax',
            method: 'post',
            parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data, //解析数据列表
                };
            },
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {field: 'title', title: '生意名称', sort: true, align: 'center'},
                {field: 'forSale', title: '待出售生意数量', sort: true, align: 'center',event:'checkforsale'},
                {field: 'selling', title: '出售中生意数量', sort: true, align: 'center',event:'checkselling'},
                {field: 'matching', title: '匹配中生意数量', sort: true, align: 'center',event:'checkMatching'},
                {field: 'needToBuy', title: '需购买数量', sort: true, align: 'center',event:'checkNeedBuy'},
                {title: '操作', toolbar: '#currentTableBar', align: 'center'}
            ]],
            limits: [ 20, 25, 30, 50, 100],
            limit: 20,
            page: false,
            skin: 'line,row',
            done: function (res, curr, count) {

            }
        });
        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');
            return false;
        });
        /*投放行业*/
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                layer.open({
                    type: 2,
                    title: '查看详情',
                    shadeClose: true,
                    shade: 0.5,
                    area: ['100%', '100%'],
                    content: '/admin/TransactionData/proportionToBeSold?action=detailView&level=' + data.level+'&canuselevel='+data.canuselevel+
                    '&title='+data.title+"&industry_id="+data.id+'&min_worth='+data.min_worth+'&max_worth='+data.max_worth,
                    end: function () {
                        location.reload();
                    }
                });
            }
            if (obj.event === 'LaunchIndustry') {
                layer.prompt({title: '输入玩家ID/手机号', formType: 0}, function (searchInfo, index) {
                    layer.close(index);
                    $.ajax({
                        url: '/admin/transactionData/searchMemberInfo',
                        type: 'post',
                        dataType: 'json',
                        async: false,
                        data: {searchInfo: searchInfo},
                        success: function (res) {
                            if (res.status == true) {
                                // 关闭弹出层
                                layer.msg(res.msg);
                                layer.open({
                                    title: '投放行业',
                                    type: 2,
                                    shade: 0.2,
                                    maxmin: true,
                                    shadeClose: true,
                                    area: ['100%', '100%'],
                                    content: '/admin/TransactionData/launchIndustry?memberInfo=' + encodeURI(JSON.stringify(res.memberInfo)) + '&level=' + data.level,
                                });
                            } else {
                                layer.msg(res.msg);
                            }
                        },
                        error: function () {
                            layer.msg("报错了");
                        }
                    });
                });
            }
            if(obj.event=='checkNeedBuy'){
                if(data.needToBuy>0){
                    layer.open({
                        type: 2,
                        title: '需购买用户',
                        shadeClose: true,
                        shade: 0.5,
                        area: ['100%', '100%'],
                        content: '/admin/Member/index?lanunchdetail=1&checkmark=1&canUseLevel='+data.canuselevel+"&checklevel="+data.level,
                        end: function () {
                        }
                    });
                }
            }
            if(obj.event=='checkselling'){
                if(data.selling>0){
                    layer.open({
                        type: 2,
                        title: '出售中用户',
                        shadeClose: true,
                        shade: 0.5,
                        area: ['100%', '100%'],
                        content: '/admin/Member/index?lanunchdetail=1&checkmark=2&canUseLevel='+data.canuselevel+"&checklevel="+data.level,
                        end: function () {
                        }
                    });
                }

            }
            if(obj.event=='checkforsale'){
                if(data.forSale>0){
                    layer.open({
                        type: 2,
                        title: '待出售用户',
                        shadeClose: true,
                        shade: 0.5,
                        area: ['100%', '100%'],
                        content: '/admin/Member/index?lanunchdetail=1&checkmark=3&canUseLevel='+data.canuselevel+"&checklevel="+data.level,
                        end: function () {
                        }
                    });
                }
            }
            if(obj.event=='checkMatching'){
                if(data.matching>0){
                    layer.open({
                        type: 2,
                        title: '匹配中用户',
                        shadeClose: true,
                        shade: 0.5,
                        area: ['100%', '100%'],
                        content: '/admin/Member/index?lanunchdetail=1&checkmark=4&canUseLevel='+data.canuselevel+"&checklevel="+data.level,
                        end: function () {
                        }
                    });
                }

            }

        });
        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'lanunch') {  // 监听添加操作
                var index = layer.open({
                    title: '投放管理',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/admin/TransactionData/lanunch_list'
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            }
        });
    });
</script>

</body>
</html>